Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

234
Vistas
Why block .catch(error => { is not run on not found error in axios request?

In laravel 9 app with axios 0.25 when making request to server

axios.post(route('frontend.get_block_cms_item'), filters)
    .then(({data}) => {
        main_page_contact_us_title.value = data.cMSItem.title
        main_page_contact_us_text.value = data.cMSItem.text
    })
    .catch(error => {
        console.error(error)
    })

I use code when item is not found :

    public function get_block_cms_item(Request $request)
    {
        $key     = $request->key;
        $cMSItem = CMSItem
            ::getByKey($key)
            ->getByPublished(true)
            ->first();
        if (empty($cMSItem)) {
            return response()->json([
                'message' => 'CMS Item with key "' . $key . '" not found !',
                404
            ]);
        }

but code .then(({data}) => is called and I got run time error :

typeError: Cannot read properties of undefined (reading 'title')

I expected that

.catch(error => {

must be run and I will not get error...

How that can be fixed ?

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda